import os
import urllib.request
from bs4 import BeautifulSoup

url = "https://sc.chinaz.com/tupian/fengjingtupian.html"

headers = {
    "User-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36"
}

request = urllib.request.Request(url, headers=headers)

response = urllib.request.urlopen(request)

content = response.read().decode("utf-8")

soup = BeautifulSoup(content, 'lxml')

html_list = soup.select("div[class='tupian-list com-img-txt-list'] img")

img_list = [f"https:{item.attrs.get('data-original')}" for item in html_list]

create_dir = "站长图片"

if not os.path.exists(create_dir):
    os.makedirs(create_dir)

for img_path in img_list:
    print(f"下载图片：{img_path}")
    urllib.request.urlretrieve(img_path, f"{create_dir}/{img_path.split("/")[-1]}")